public class Solution3 {
    //判断链表是否为回文结构
    public boolean chkPalindrome(ListNode head) {
        //找到中间位置的结点
        ListNode slow = toFindMiddleNode(head);
        //反转中间结点之后的结点
        ListNode cur = slow.next;
        while(cur != null) {
            ListNode curN = cur.next;
            cur.next = slow;
            cur = curN;
            slow = cur;
        }
        //遍历数组，判断是否为回文
        while(head != slow) {
            if(head.val != slow.val) {
                return false;
            }
            if(head.next == slow) {
                return true;
            }
            head = head.next;
            slow = slow.next;
        }
        return true;
    }
    private ListNode toFindMiddleNode(ListNode head) {
        ListNode cur = head;
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
}
